<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>定时计划js动态脚本语法参详</title>
</head>
<style>
    div {margin: 10px}
    i{background-color: #9E9E9E}
    b{font-size: 14px;}
    h3{border: blue 1px dashed; }
</style>
<script type="text/javascript">

    function showJson(json){
        return "<pre>"+syntaxHighlight(json)+"</pre>"
    }

    // 方法实现
    function syntaxHighlight(json) {
        if (typeof json != 'string') {
            json = JSON.stringify(json, undefined, 2); //返回要JSON化的对象，2是spacing
        }
        json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
        return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,
            function (match) {
                var cls = 'number';
                if (/^"/.test(match)) {
                    if (/:$/.test(match)) {
                        cls = 'key';
                    } else {
                        cls = 'string';
                    }
                } else if (/true|false/.test(match)) {
                    cls = 'boolean';
                } else if (/null/.test(match)) {
                    cls = 'null';
                }
                return '<span style="color: green;">' + match + '</span>';
            }
        );
    }
</script>
<body>
<h1>支持js es5语法,参考函数如下</h1>
<p style="color: #9E9E9E">采用java nashorn script engine,进行解析!支持原生JSON.parse等之类的部分函数。</p>
<div>
    <h3>sql读取处理</h3>
    <p>
        api.querySql(String sql,Object[] ps)
    </p>
    <i>var data = api.querySql("select * from aaa where url=?",["param1"])</i>
</div>
<div>
<h3>日志打印</h3>
    <p>
        api.log(Object info)
    </p>
    <i>api.log("输出一段文字到日志中...")</i>
</div>
<h3>错误打印</h3>
<p>
    api.error(Object info)
</p>
<i>api.error("输出一段文字到日志中...")</i>
<h3>调试打印</h3>
<p>
    api.debug(Object info)
</p>
<i>api.debug("只显示到node的本地日志中,无法从web控制台上看到...")</i>
<div>
    <h3>动态参数</h3>
    <p>
        api.ps.?
    </p>
    <b>通用参数: job</b>
    <p>job对象:
        <script type="text/javascript">
            document.write(showJson({"id":229,"report_name":"测试_2022_10_01_22_52_19","tran_id":"2022_10_01_22_52_19","task_id":2,"nodes":"LAPTOP-7V5D9SQE","nodes_info":"[{\"node\":\"LAPTOP-7V5D9SQE\",\"cpu\":8,\"memory\":16048,\"threads\":1}]","filter_table":"2022_10_01_22_52_19-2.sample","filter_store":"mysql","begin_time":"2022-10-01 22:52:19","end_time":"1900-01-01 00:00:00","create_time":"2022-10-01 22:52:19","report_node_table":"auto_tb_report_node_2022_10_01_22_52_19","report_url_table":"auto_tb_report_url_2022_10_01_22_52_19","task_name":"测试","filter_table_lines":0,"filter_table_error_lines":0}
            ));
        </script>
    </p>
</div>
<div>
    <h3>睡眠n毫秒</h3>
    <p>
        api.sleep(Integer time),谨慎使用!
    </p>
    <i>api.sleep(5)</i>
</div>
<div>
    <h3>当前时间格式化</h3>
    <p>
        api.nowFormat(String format)
    </p>
    <i>api.nowFormat("yyyy-MM-dd")</i>
</div>
<div>
    <h3>http Post Json请求支持,返回String</h3>
    <p>
        api.httpPost(String url,Object json)
    </p>
    <i>var result=api.httpPost("http://www.baidu.com/",{"aa":111})</i>
</div>
<div>
    <h3>http Post Form请求支持,返回String</h3>
    <p>
        api.httpPostForm(String url,Object form)
    </p>
    <i>无,注意:没测试过,不建议使用</i>
</div>
<div>
    <h3>http Get请求支持,返回String</h3>
    <p>
        api.httpGet(String url)
    </p>
    <i>var result=api.httpGet("http://wwww.baidu.com/")</i>
</div>
<div>
    <h3>openTask 启动任务</h3>
    <p>
        api.openTask(Integer taskid)
    </p>
    <i>api.openTask(1)</i>
</div>
<div>
    <h3>openTask 启动任务,可传入任务动态参数</h3>
    <p>
        api.openTask2(Integer taskid,Object params)
    </p>
    <i>api.openTask2(1,{"aaa":"test"})</i>
</div>
<div>
    <h3>closeTask 关闭任务</h3>
    <p>
        api.closeTask(Integer taskid)
    </p>
    <i>api.closeTask(1)</i>
</div>
<div>
    <h3>isTaskRunning 任务运行中判断</h3>
    <p>
        api.isTaskRunning(Integer taskid)
    </p>
    <i>var isRunning = api.isTaskRunning(1)</i>
</div>
<div>
    <h3>isTaskExist 任务是否存在判断</h3>
    <p>
        api.isTaskExist(Integer taskid)
    </p>
    <i>var exist = api.isTaskExist(1)</i>
</div>
</body>
</html>